package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.service.impl.EduCourseServiceImpl;
import com.jf3q.common.service.impl.EduSubjectServiceImpl;
import com.jf3q.common.service.impl.EduTeacherServiceImpl;
import com.jf3q.common.vo.CourseandTea;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.common.vo.SubjectVo;
import com.jf3q.front.dto.pageCourse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.List;

@RestController
@Tag(name = "课程")
public class CourseController {

    @Autowired
    EduSubjectServiceImpl eduSubjectService;
    @Autowired
    EduCourseServiceImpl eduCourseService;

    @Autowired
    EduTeacherServiceImpl eduTeacherService;

    @PostMapping("/eduservice/coursefront/getFrontCourseList/{page}/{limit}")
    @Operation(summary = "课程分页")
    public ResultVo getFrontCourseList(@PathVariable Integer page,
                                       @PathVariable Integer limit, @RequestBody pageCourse course) {

        LambdaQueryWrapper<EduCourse> wrapper = new LambdaQueryWrapper<>();

        if (course != null) {
            if (!ObjectUtils.isEmpty(course.getSubjectParentId())) {
                wrapper.like(EduCourse::getSubjectParentId, course.getSubjectParentId());
            }
            if (!ObjectUtils.isEmpty(course.getSubjectId())) {
                wrapper.like(EduCourse::getSubjectId, course.getSubjectId());
            }
            if (!ObjectUtils.isEmpty(course.getGmtCreateSort())) {
                wrapper.orderByDesc(EduCourse::getEduCreate);
            }
            if (!ObjectUtils.isEmpty(course.getBuyCountSort())) {
                wrapper.orderByDesc(EduCourse::getBuyCount);
            }
            if (!ObjectUtils.isEmpty(course.getPriceSort())) {
                wrapper.orderByDesc(EduCourse::getPrice);
            }
            if (!ObjectUtils.isEmpty(course.getCourseName())) {
                wrapper.like(EduCourse::getTitle,course.getCourseName());
            }
        }
        Page<EduCourse> page1 = eduCourseService.page(new Page<>(page, limit), wrapper);


        return ResultVo.success("",page1);


    }

    @GetMapping("/courseandTeacher")
    public ResultVo courseandTeacher(){

        CourseandTea courseandTea = new CourseandTea();

        List<EduTeacher> eduTeachers = eduTeacherService.selectTea();

        List<EduCourse> eduCourses = eduCourseService.selectTeacher();

        courseandTea.setEduList(eduCourses);

        courseandTea.setTeacherList(eduTeachers);

        return ResultVo.success("",courseandTea);

    }

    @GetMapping("/eduservice/subject/getAllSubject")
    public ResultVo subjectList(){
        List<SubjectVo>subjectVos=eduSubjectService.getList();
        return ResultVo.success("",subjectVos);
    }
}
